﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_FriendLink
{
    public partial class LinkCategory : AdminPage
    {
        private FriendLink curFriendLink = new FriendLink();
        private FriendLinkClass curFriendLinkClass = new FriendLinkClass();
        //private Dictionary<string, string> dic = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            if (!IsPostBack)
            {
                try
                {
                    DdlMenu_bind();
                }
                catch (Exception ex) { Response.Redirect("../Message.aspx?message=绑定异常！" + ex.Message + "&z=no"); }
            }
        }



        #region 类别数据绑定
        void DdlMenu_bind()
        {
            DataTable dt = curFriendLinkClass.GetList();
            this.DdlMenu.Items.Clear();
            this.DdlMenu.Items.Add(new ListItem("请选择所属分类", ""));
            foreach(DataRow dr in dt.Rows)
            {
                string clsno=dr["clsno"].ToString();
                string clsname=dr["clsname"].ToString();
                ListItem li = new ListItem(clsname, clsno);
                DdlMenu.Items.Add(li);
            }
            DdlMenu.Attributes.Add("onchange", "SwapText();");
        }
        #endregion


        protected void btnAdd_Click(object sender, EventArgs e)
        {
            FriendLinkClassInfo model = new FriendLinkClassInfo();
            model.clsno = txtClsno.Text.Trim(); //PlugNT.Common.Utils.GetDateTimeCode();
            model.clsname = txtClsname.Text;
            if (curFriendLinkClass.Add(model))
            {
                Response.Redirect("../Message.aspx?message=添加成功！&z=yes");
            }
            else
            {
                Response.Redirect("../Message.aspx?message=添加失败！&z=no");
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string no = DdlMenu.SelectedValue.Trim();
            if (no != "")
            {
                FriendLinkClassInfo model = new FriendLinkClassInfo();
                model.clsno = no;
                model.clsname = txtClsname.Text;
                if (curFriendLinkClass.Update(model))
                {
                    Response.Redirect("../Message.aspx?message=修改成功！&z=yes");
                }
                else
                {
                    Response.Redirect("../Message.aspx?message=修改失败！&z=no");
                }
            }
            else
            {
                Response.Redirect("../Message.aspx?message=修改失败！&z=no");
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string no = DdlMenu.SelectedValue.Trim();
            if (no != "")
            {
                if (curFriendLinkClass.Delete(no))
                {
                    Response.Redirect("../Message.aspx?message=删除成功！&z=yes");
                }
                else
                {
                    Response.Redirect("../Message.aspx?message=删除失败！&z=no");
                }
            }
            else
            {
                Response.Redirect("../Message.aspx?message=删除失败，请选择要删除的类别！&z=no");
            }
        }


    }
}
